package com.chen.webuser.controller;

import com.chen.util.Check;
import com.chen.util.Result;
import com.chen.util.ResultCode;
import com.chen.webuser.entity.WebUser;
import com.chen.webuser.entity.dto.LoginDto;
import com.chen.webuser.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author chen
 * @since 2025-10-19
 */
@RestController
public class LoginController {

    @Autowired
    private LoginService loginService;

    /**
     * 注册
     */
    @PostMapping("/register")
    public Result register(@RequestBody WebUser webUser) {
        Check.checkParameter(webUser);
        loginService.register(webUser);
        return Result.build(null, ResultCode.SUCCESS);
    }


    /**
     * 登录
     */
    @PostMapping("/login")
    public Result usernamePasswordLogin(@RequestBody LoginDto loginDto) {
        Check.checkParameter(loginDto);
        WebUser webUser = loginService.login(loginDto);
        return Result.build(webUser);
    }

}
